package com.quad.innovators.salesease.controller.warehouse;

import com.quad.innovators.salesease.annotation.DataPermission;
import com.quad.innovators.salesease.annotation.FunctionPermission;
import com.quad.innovators.salesease.annotation.Log;
import com.quad.innovators.salesease.annotation.RepeatSubmit;
import com.quad.innovators.salesease.common.result.PageResultBean;
import com.quad.innovators.salesease.common.result.Result;
import com.quad.innovators.salesease.constants.SystemConstants;
import com.quad.innovators.salesease.enums.LogModuleEnum;
import com.quad.innovators.salesease.model.form.warehouse.SaleReturnOrderForm;
import com.quad.innovators.salesease.model.form.warehouse.VehicleBringGoodsForm;
import com.quad.innovators.salesease.model.query.warehouse.VehicleBringGoodsPageQuery;
import com.quad.innovators.salesease.model.vo.warehouse.SaleReturnOrderVO;
import com.quad.innovators.salesease.model.vo.warehouse.VehicleBringGoodsVO;
import com.quad.innovators.salesease.service.warehouse.VehicleBringGoodsService;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;

/**
 * @author : shanshan.li
 * @createTime : 2025/4/3 09:52
 * @Version : 1.0 
 */
@Tag(name = "17.车辆带货")
@RestController
@RequestMapping(SystemConstants.BACKEND_API + "/vehicle-bring-goods")
@RequiredArgsConstructor
public class VehicleBringGoodsController {
    private final VehicleBringGoodsService vehicleBringGoodsService;

    @Operation(summary = "分页列表")
    @GetMapping("/page")
    @Log(value = "分页列表", module = LogModuleEnum.VEHICLE_BRING_GOODS)
    @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<PageResultBean<VehicleBringGoodsVO>> listPaged(VehicleBringGoodsPageQuery queryParams) {
        PageResultBean<VehicleBringGoodsVO> result = vehicleBringGoodsService.listPage(queryParams);
        return Result.success(result);
    }

    @Operation(summary = "表单数据")
    @GetMapping("/{code}/form")
    @Parameters({
            @Parameter(name = "code", description = "code"),
    })
    @FunctionPermission(permissionCode = "warehouse:vehicle-bring-goods:detail")
    @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<VehicleBringGoodsForm> getForm(@PathVariable("code") String code) {
        VehicleBringGoodsForm formData = vehicleBringGoodsService.getFormData(code);
        return Result.success(formData);
    }

    @Operation(summary = "新增")
    @PostMapping
    @FunctionPermission(permissionCode = "warehouse:vehicle-bring-goods:add")
    @RepeatSubmit
    public Result<?> save(@RequestBody @Valid VehicleBringGoodsForm form) {
        boolean result = vehicleBringGoodsService.save(form);
        return Result.success(result);
    }

    @Operation(summary = "修改")
    @PutMapping(value = "/{code}")
    @Parameters({
            @Parameter(name = "code", description = "code")
    })
    @FunctionPermission(permissionCode = "warehouse:vehicle-bring-goods:edit")
    @DataPermission(permissionCode = "warehouse:vehicle-bring-goods:data-permission")
    public Result<?> update(@PathVariable("code") String code, @RequestBody @Validated VehicleBringGoodsForm form) {
        boolean result = vehicleBringGoodsService.update(code, form);
        return Result.success(result);
    }

    @Operation(summary = "校验")
    @PutMapping(value = "/{code}/examine")
    @Parameters({
            @Parameter(name = "code", description = "code")
    })
    @FunctionPermission(permissionCode = "warehouse:vehicle-bring-goods:edit")
    public Result<?> examineResult(@PathVariable("code") String code) {
        boolean result = vehicleBringGoodsService.examineResult(code);
        return Result.success(result);
    }
}
